﻿using System.Configuration;
using System.Data;
using System.Windows;

namespace StockCalc
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {

        public static void LocationWindow2ScreenCenter(Window destWindow)
        {
            double screenWidth = SystemParameters.PrimaryScreenWidth;
            double screenHeight = SystemParameters.PrimaryScreenHeight;
            double windowWidth = destWindow.Width;
            double windowHeight = destWindow.Height;

            // 如果窗口尚未被渲染，则使用默认的尺寸（可能是从XAML中定义的）  
            if (windowWidth == 0) windowWidth = destWindow.RestoreBounds.Width;
            if (windowHeight == 0) windowHeight = destWindow.RestoreBounds.Height;

            double left = (screenWidth - windowWidth) / 2;
            double top = (screenHeight - windowHeight) / 2;

            destWindow.Left = left;
            destWindow.Top = top;
        }

    }

    

}
